package com.zhongxin.wymovieticket;

import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.zhoujing.Entity.CineaMovie;
import com.zhoujing.Entity.Cinema;
import com.zhoujing.utils.JsonUtils;
import com.zhoujing.utils.JsonUtils.JsonObjectCallBack;

public class CinemaDetaileActivity extends Activity {

	private int cinema_id;
	private String url;
	private RequestQueue queue;
	private Bundle bundle;
	private Cinema cinema;
	private ProgressDialog dialog;
	private ScrollView pullScrollView;
	private TextView txttitle;
	private TextView txtfavor;
	private TextView txtcinema;
	private ImageView imaxiImageView;
	private TextView txtscore;
	private TextView textAddress;
	private ImageView detailiImageView;
	private LinearLayout layoutquan;
	private TextView txtquandescrip;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_cinema_detaile);
		
		Intent intent=getIntent();
		bundle = intent.getBundleExtra("bundle");
		cinema = (Cinema) bundle.getSerializable("cinemaDetailEntity");
		queue=Volley.newRequestQueue(this);
	    cinema_id=cinema.getId();
	    url="http://piao.163.com/m/cinema/schedule.html?movie_id=&cinema_id="+cinema_id+"&apiVer=14&mobileType=android&deviceId=08:00:27:f4:e2:00&channel=netease&ver=4.8&city=440300";
		//下载数据
		getData();
		/**
		 * 设置对话框
		 */
		dialog=new ProgressDialog(this);
		dialog.setMessage("正在加载,请稍后......");
		
		Log.i("-----------", "--------------"+cinema.getName());
		initView();
        
	}

	private void getData() {
		// TODO Auto-generated method stub
		JsonUtils.parseJsonObject(this, url, new JsonObjectCallBack() {
			
			@Override
			public void jsonObjectCallBack(JSONObject jsonObject) {
				// TODO Auto-generated method stub
				Log.i("", "-------cineadetailactivity-------"+jsonObject.toString());
				CineaMovie cineaMovie=new CineaMovie();
				cineaMovie=JSON.parseObject(jsonObject.toString(),CineaMovie.class);
				Log.i("", "-------cineadetailactivity-------"+cineaMovie.getRetcode());
				
			}
		}, queue);
	}

	private void initView() {
		pullScrollView = (ScrollView) this.findViewById(R.id.cinea_detail_scrollView);
		txttitle = (TextView) pullScrollView.findViewById(R.id.activity_tongyong_textview);
		//设置电影院名称
		txttitle.setText(cinema.getName());
		txtfavor = (TextView) pullScrollView.findViewById(R.id.favor_textview);
		txtfavor.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO 跳登录界面
				Toast.makeText(CinemaDetaileActivity.this, "登录了", 1).show();
				
			}
		});
		//设置电影院名称
		txtcinema = (TextView) pullScrollView.findViewById(R.id.tv_list_name2);
		txtcinema.setText(cinema.getName());
		//是否是imax
		imaxiImageView = (ImageView) pullScrollView.findViewById(R.id.icon_is_imax);
		if (cinema.getIsImaxSupport()==0) {
			imaxiImageView.setVisibility(View.GONE);
		}else {
			imaxiImageView.setVisibility(View.VISIBLE);
		}
		//设置分数
		txtscore = (TextView) pullScrollView.findViewById(R.id.tv_cinema_score);
		txtscore.setText(cinema.getGrade()+"分");
		txtscore.setTextColor(Color.YELLOW);
		
		//地址
		
		textAddress = (TextView) pullScrollView.findViewById(R.id.tv_list_address2);
		textAddress.setText(cinema.getAddress());
		
		//点击跳转电影院详情
		
		detailiImageView = (ImageView) pullScrollView.findViewById(R.id.cinema_detail_tiaozhuan);
		detailiImageView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Toast.makeText(CinemaDetaileActivity.this, "跳转到详情界面", 1).show();
			}
		});
		//把电影院的详细信息
		//把券显示出来,这个是要隐藏起来的
		layoutquan = (LinearLayout) pullScrollView.findViewById(R.id.layout_cgs);
		if (cinema.getIsCouponSupport()==1) {
			layoutquan.setVisibility(View.VISIBLE);
			txtquandescrip = (TextView) pullScrollView.findViewById(R.id.coupon_descripe);
			txtquandescrip.setText(cinema.getLowPrice()+"起");
		}else {
			layoutquan.setVisibility(View.GONE);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.cinema_detaile, menu);
		return true;
	}
      

}
